#include "modelviewdialog.h"
#include "ui_modelviewdialog.h"

#include <QStringList>

ModelViewDialog::ModelViewDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ModelViewDialog)
{
    ui->setupUi(this);
    setFixedSize(size());
    model = new QStringListModel(this);
    QStringList List;
    List << "Clair de Lune" << "Reverie" << "Prelude";
    model->setStringList(List);

    ui->listView->setModel(model);
    ui->comboBox->setModel(model);

    ui->listView->setEditTriggers(QAbstractItemView::DoubleClicked |
                                  QAbstractItemView::AnyKeyPressed);

}

ModelViewDialog::~ModelViewDialog()
{
    delete ui;
}

void ModelViewDialog::on_pushButton_clicked()
{
    // Add Button clicked.

    int row = model->rowCount();
    model->insertRows(row, 1);

    QModelIndex index = model->index(row);
    ui->listView->setCurrentIndex(index);
    ui->listView->edit(index);
}

void ModelViewDialog::on_pushButton_2_clicked()
{
    // Insert Button clicked.

    int row = ui->listView->currentIndex().row();
    model->insertRows(row, 1);

    QModelIndex index = model->index(row);
    ui->listView->setCurrentIndex(index);
    ui->listView->edit(index);
}

void ModelViewDialog::on_pushButton_3_clicked()
{
    // Delete  Button Clicked.
    model->removeRows(ui->listView->currentIndex().row(), 1);
}
